<?php
/**
* @version      $Id: plan.php 7 2009-11-14 07:39:39Z allytools $
* @package      Joomla
* @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license      GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

class JElementPlan extends JElement
{
    /**
     * Element name
     *
     * @access  protected
     * @var     string
     */
    var $_name = 'Plan';

    function fetchElement($name, $value, &$node, $control_name)
    {
        $db = &JFactory::getDBO();

        $query = 'SELECT p.id AS id, CONCAT(p.name, " (", p.id, ")") AS text'
        . ' FROM #__wh_plans AS p'
        . ' LEFT JOIN #__categories AS c ON c.id = p.catid '
        . ' WHERE p.published = 1 AND (c.published = 1 OR p.catid = 0)'
        . ' ORDER BY c.ordering, p.ordering'
        ;

        $db->setQuery( $query );
        $options = $db->loadObjectList( );

        return JHTML::_('select.genericlist',  $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'id', 'text', $value, $control_name.$name );
    }
}